package gui;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JButton;

//class to button used in the program menus
public class GameButton extends JButton{

	private static final long serialVersionUID = 1L;
	private int index;
	
	public static int DEFAULT_WIDTH = 100, DEFAULT_HEIGHT = 28;
	
	//it returns with the index of the button
	public int getIndex(){
		return index;
	}
	
	//button constructor
	public GameButton(String buttonText, int x, int y, int width, int height){
		super(buttonText);
		setBounds(x, y, width, height);
		setFont(new Font("Arial", Font.PLAIN, height / 5 * 3));
	}
	
	//button constructor
	public GameButton(String buttonText, int x, int y){
		super(buttonText);
		setBounds(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT);
		setFont(new Font("Arial", Font.PLAIN, 28 / 5 * 3));
	}
	
	//button constructor
	public GameButton(String buttonText){
		super(buttonText);
	}
	
	//overriding method for lookout changing
	public void paintComponent(Graphics g){
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
		if(getModel().isPressed())
			g2.setColor(GameConstants.COMPONENT_COLOR_PRESSED);
		else
			g2.setColor(GameConstants.COMPONENT_COLOR);
		g2.fillRect(0, 0, getWidth(), getHeight());
		g2.setColor(GameConstants.COMPONENT_TEXT);
		g2.drawString(
				getText(),
				( getWidth() - getFontMetrics(getFont()).stringWidth(getText()) ) / 2,
				getFontMetrics(getFont()).getHeight() );
		
		super.paintComponents(g2);
	}
	
	//overriding method for lookout changing
	public void paintBorder(Graphics g){
		if(getModel().isRollover())
			g.setColor(GameConstants.COMPONENT_BORDER_OVER);
		else
			g.setColor(GameConstants.COMPONENT_BORDER);
		g.drawRect(1, 1, getWidth()-3, getHeight()-3);
		super.paintComponents(g);
	}

}